function showChildAreaPlace(selector, type, targetId, sourceId){
	var parentid = $(selector).val();
	if(sourceId){
		_selectArea(selector, sourceId);
	}
	_createPlaceOptions(targetId, type, parentid);
}

function showParentPlace(selector, targetId){
	var type =  $(selector).val();
	_createPlaceOptions(targetId, type, null);
}

function _createPlaceOptions(targetId, type, parentid){
	$.ajax({
	 type: "POST",
	 url: "./backoffice/area/ajaxGetSelectArea.do",
	 data: {
	    "type": type,
	    "parentid" : parentid
	 },
	 dataType: 'json',
	 success: function(msg){
	   if(msg.result == 'success') {
	      if(msg.resultObjs != null){
	        var placeList = msg.resultObjs;
	        var selector = $("#" + targetId);
	        selector.empty();//清空select下拉框
	        $("<option value=''>请选择</option>").appendTo(selector);  
	        for(var i=0; i< placeList.length; i++){
	        	var place = msg.resultObjs[i];
	        	if(place != null && place.pid != '1-01'){
	        		$('<option>',{
			            val:place.areaid,
			            text:place.name
					}).appendTo(selector);
	        	}
	        }
	      }
	   }
	   else {
	      alert("无法取得景区");
       }
	 }
   });
}
	
	
function _selectOptionItem(elementId, value){
  var element = document.getElementById(elementId);
  var options = element.options;
  for (var i = 0; i < options.length; i++) {
    if(options[i].value == value){
      options[i].selected = true;
      break;
    }    
  }
}
	
function _initPlaceOptions(contientid, countryId, areaid){
	if(contientid != null && contientid.length > 0){
		setTimeout(function() {
			_selectOptionItem("ppareaid", contientid);
			showChildAreaPlace("#ppareaid", "g", "pareaid", countryId);
		}, 500);
    }
    if(countryId != null && countryId.length > 0){
		setTimeout(function() {
			_selectOptionItem("pareaid", countryId);
			showChildAreaPlace("#pareaid", "s", "areaid", areaid);
		}, 1000);
    }
	if(areaid != null && areaid.length > 0){
		setTimeout(function() {
			_selectOptionItem("areaid", areaid);
		}, 1200);
  	}
}

function _selectArea(selector, targetId){
  var pid = $(selector).val();
  $("[name='"+ targetId +"'][id='" + targetId + "']").val(pid);
}


